
using System;
using System.Collections.Generic;
using WooEngine.Utility.Security.Base;

/**
 * 以RTGameRandom制作的静态random工具类，默认种子以当前时间的long制作,所以在第一次创建此函数时，种子就确定了
 * 可以在中途进行改变
 */
namespace WooEngine.Utility.Random
{
	public class RTGameRandomUtils
	{
		private static RTGameRandom inst = new RTGameRandom (DateTime.UtcNow.Ticks);
		
		/**
		 * 改变种子的方法
		 * @param value 种子为long
		 */
		public static long Seed {
			get { return inst.GetGameSeed (); }
			set { inst.SetGameSeed (value); }
		}
		
		public static bool Hit(int possibility, int denominator) {
			return inst.Hit(possibility, denominator);
		}
		
		public static float RandomFloat(int max) {
			return inst.RandomFloat(max);
		}
		
		public static float RandomFloat(float max) {
			return inst.RandomFloat(max);
		}
		
		public static int RandomRange(int min, int max) {
			return inst.RandomRange(min, max);
		}
		
		public static float RandomFloatRange(int min, int max) {
			return inst.RandomFloatRange(min, max);
		}
		
		public static float RandomFloatRange(float min, float max) {
			return inst.RandomFloatRange(min, max);
		}

		public static int RandomInt(int max) {
			return inst.RandomInt(max);
		}

		
		public static  int RandomByWeights(params int[] weights) {
			return inst.RandomByWeights(weights);
		}

		public static EncryptInt RandomByWeights(params EncryptInt[] weights)
		{
			return inst.RandomByWeights(weights);
		}

		public static int RandomByWeightsAndExcepts(int[] excepts, params int[] weights)
		{
			return inst.RandomByWeightsAndExcepts(excepts, weights);
		}

		public static EncryptInt RandomByWeightsAndExcepts(int[] excepts, params EncryptInt[] weights)
		{
			return inst.RandomByWeightsAndExcepts(excepts, weights);
		}

		

		public static int RandomByWeights(int sum, params int[] weights) {
			return inst.RandomByWeights(sum, weights);
		}

        
        public static List<T> RandomArr<T>(List<T> list, int num)
        {
            return RandomArr<T>(list.ToArray(), num);
        }

        public static List<T> RandomArr<T>(T[] list, int num)
        {
			List<T> tempList = new List<T>();
			for(int i = 0; i < list.Length; i++)
            {
				tempList.Add(list[i]);
            }
			int removeNum = list.Length - num;
			if (removeNum <= 0)
				return tempList;
			for (int i = 0; i < removeNum; i++)
            {
				tempList.RemoveAt(RandomInt(tempList.Count - 1));

			}
            return tempList;
        }

        public static List<T> RandomArrByWeights<T>( T[] list , int num , int[] weights )
        {
            List<T> retList = new List<T>();
            List<int> tempList = new List<int>();
            for (int i = 0; i < num; i++)
            {
                int index = RandomByWeightsAndExcepts(tempList.ToArray(), weights);
                tempList.Add(index);
                retList.Add( list[index] );
            }
            return retList;
        }
    } 
}
